Move console tty/limit information into console directory in domain dir.
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Wed, 7 Sep 2005 21:24:34 +0000 (21:24 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Wed, 7 Sep 2005 21:24:34 +0000 (21:24 +0000)
Also only store port number of console event channel.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
tools/console/client/main.c
tools/console/daemon/io.c
tools/python/xen/xend/XendCheckpoint.py
tools/python/xen/xend/XendDomainInfo.py

index 512e08a8074a80ba1a200b8ae02ce97c919a56ef..4c7b2710b82db2613decd5a9ccba1141960a9f29 100644 (file)
@@ -170,8 +170,7 @@ int main(int argc, char **argv)
                { 0 },
 
        };
-       char *str_pty;
-       char path[1024];
+       char *str_pty, *path;
        int spty;
        unsigned int len = 0;
        struct xs_handle *xs;
@@ -214,7 +213,13 @@ int main(int argc, char **argv)
        
        signal(SIGTERM, sighandler);
 
-       snprintf(path, sizeof(path), "/console/%d/tty", domid);
+       path = xs_get_domain_path(xs, domid);
+       if (path == NULL)
+               err(errno, "xs_get_domain_path()");
+       path = realloc(path, strlen(path) + strlen("/console/tty") + 1);
+       if (path == NULL)
+               err(ENOMEM, "realloc");
+       strcat(path, "/console/tty");
        str_pty = xs_read(xs, path, &len);
 
        /* FIXME consoled currently does not assume domain-0 doesn't have a
@@ -252,6 +257,7 @@ int main(int argc, char **argv)
                err(errno, "Could not open tty `%s'", str_pty);
        }
        free(str_pty);
+       free(path);
 
        init_term(STDIN_FILENO, &attr);
        console_loop(xc_handle, domid, spty);
index 8f8f50ceee6d12577d27b264a8b4b826ce05d118..08aeda1c468c79e15b12ee44086537ff277c1f31 100644 (file)
@@ -144,6 +144,7 @@ static int domain_create_tty(struct domain *dom)
 {
        char *path;
        int master;
+       bool success;
 
        if ((master = getpt()) == -1 ||
            grantpt(master) == -1 || unlockpt(master) == -1) {
@@ -161,11 +162,17 @@ static int domain_create_tty(struct domain *dom)
                        tcsetattr(master, TCSAFLUSH, &term);
                }
 
-               asprintf(&path, "/console/%d/tty", dom->domid);
-               xs_write(xs, path, slave, strlen(slave), O_CREAT);
+               success = asprintf(&path, "%s/tty", dom->conspath) != -1;
+               if (!success)
+                       goto out;
+               success = xs_write(xs, path, slave, strlen(slave), O_CREAT);
                free(path);
+               if (!success)
+                       goto out;
 
-               asprintf(&path, "/console/%d/limit", dom->domid);
+               success = asprintf(&path, "%s/limit", dom->conspath) != -1;
+               if (!success)
+                       goto out;
                data = xs_read(xs, path, &len);
                if (data) {
                        dom->buffer.max_capacity = strtoul(data, 0, 0);
@@ -175,6 +182,9 @@ static int domain_create_tty(struct domain *dom)
        }
 
        return master;
+ out:
+       close(master);
+       return -1;
 }
 
 /* Takes tuples of names, scanf-style args, and void **, NULL terminated. */
@@ -218,7 +228,7 @@ static int domain_create_ring(struct domain *dom)
 
        err = xs_gather(xs, dom->conspath,
                        "ring-ref", "%u", &ring_ref,
-                       "console_channel/port1", "%i", &local_port,
+                       "port", "%i", &local_port,
                        NULL);
        if (err)
                goto out;
@@ -289,6 +299,17 @@ static struct domain *create_domain(int domid)
        }
 
        dom->domid = domid;
+
+       dom->conspath = xs_get_domain_path(xs, dom->domid);
+       if (dom->conspath == NULL)
+               goto out;
+       s = realloc(dom->conspath, strlen(dom->conspath) +
+                   strlen("/console") + 1);
+       if (s == NULL)
+               goto out;
+       dom->conspath = s;
+       strcat(dom->conspath, "/console");
+
        dom->tty_fd = domain_create_tty(dom);
        dom->is_dead = false;
        dom->buffer.data = 0;
@@ -302,18 +323,6 @@ static struct domain *create_domain(int domid)
        dom->page = NULL;
        dom->evtchn_fd = -1;
 
-       dom->conspath = NULL;
-
-       dom->conspath = xs_get_domain_path(xs, dom->domid);
-       if (dom->conspath == NULL)
-               goto out;
-       s = realloc(dom->conspath, strlen(dom->conspath) +
-                   strlen("/console") + 1);
-       if (s == NULL)
-               goto out;
-       dom->conspath = s;
-       strcat(dom->conspath, "/console");
-
        if (!watch_domain(dom, true))
                goto out;
 
index 7a0f43fc7d2b1e80d84344b22970c08884f2464b..345f83979d1b91a56ff233950d7f27ec8aa5e2cb 100644 (file)
@@ -173,7 +173,6 @@ def restore(xd, fd):
                     if m:
                         dominfo.console_mfn = int(m.group(2))
                         dominfo.exportToDB(save=True, sync=True)
-                        dominfo.publish_console()
                     try:
                         l = child.fromchild.readline()
                     except:
index e954fad70f1d27ae3bd954748251e367e993970c..1100d28b850e12300d2150b302df98bb9bb72989 100644 (file)
@@ -298,15 +298,14 @@ class XendDomainInfo:
             self.store_channel.saveToDB(self.db.addChild("store_channel"),
                                         save=save)
         if self.console_channel:
-            self.console_channel.saveToDB(self.db.addChild("console/console_channel"),
-                                        save=save)
+            self.db['console/port'] = "%i" % self.console_channel.port1
         if self.image:
             self.image.exportToDB(save=save, sync=sync)
         self.db.exportToDB(self, fields=self.__exports__, save=save, sync=sync)
 
     def importFromDB(self):
         self.db.importFromDB(self, fields=self.__exports__)
-        self.store_channel = self.eventChannel("store_channel")
+        self.store_channel = self.eventChannelOld("store_channel")
 
     def setdom(self, dom):
         """Set the domain id.
@@ -654,7 +653,6 @@ class XendDomainInfo:
             self.configure_restart()
             self.construct_image()
             self.configure()
-            self.publish_console()
             self.exportToDB(save=True)
         except Exception, ex:
             # Catch errors, cleanup and re-raise.
@@ -845,7 +843,7 @@ class XendDomainInfo:
                   id, self.name, self.memory)
         self.setdom(id)
 
-    def eventChannel(self, key):
+    def eventChannelOld(self, key):
         """Create an event channel to the domain.
         If saved info is available recreate the channel.
         
@@ -854,11 +852,27 @@ class XendDomainInfo:
         db = self.db.addChild(key)
         return EventChannel.restoreFromDB(db, 0, self.id)
         
+    def eventChannel(self, path=None, key=None):
+        """Create an event channel to the domain.
+        
+        @param path under which port is stored in db
+        """
+        port = 0
+        try:
+            if path and key:
+                if path:
+                    db = self.db.addChild(path)
+                else:
+                    db = self.db
+                port = int(db[key].getData())
+        except: pass
+        return EventChannel.interdomain(0, self.id, port1=port, port2=0)
+        
     def create_channel(self):
         """Create the channels to the domain.
         """
-        self.store_channel = self.eventChannel("store_channel")
-        self.console_channel = self.eventChannel("console/console_channel")
+        self.store_channel = self.eventChannelOld("store_channel")
+        self.console_channel = self.eventChannel("console", "port")
 
     def create_configured_devices(self):
         devices = sxp.children(self.config, 'device')
@@ -1071,11 +1085,6 @@ class XendDomainInfo:
             backend = blkif.getBackend(0)
             backend.connect(recreate=self.recreate)
 
-    def publish_console(self):
-        db = DBMap(db=XenNode("/console/%d" % self.id))
-        db['domain'] = self.db.getPath()
-        db.saveDB(save=True)
-
     def configure_fields(self):
         """Process the vm configuration fields using the registered handlers.
         """
@@ -1143,7 +1152,7 @@ class XendDomainInfo:
 
     def dom0_init_store(self):
         if not self.store_channel:
-            self.store_channel = self.eventChannel("store_channel")
+            self.store_channel = self.eventChannelOld("store_channel")
         self.store_mfn = xc.init_store(self.store_channel.port2)
         if self.store_mfn >= 0:
             self.db.introduceDomain(self.id, self.store_mfn,